package gentle.controller;

import com.baomidou.mybatisplus.plugins.Page;
import gentle.base.BaseController;
import gentle.entity.ReturnVisitInfo;
import gentle.entity.SearchReturnVisitInfo;
import gentle.factory.PageFactory;
import gentle.service.IConsultantDiagnosisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;



@RestController
@RequestMapping("diagnosis")
public class ConsultantDiagnosisController extends BaseController {

    @Autowired
    IConsultantDiagnosisService consultantDiagnosisService;

    /**
     * tc看诊记录列表加载
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object consultantInfoList(SearchReturnVisitInfo info, HttpServletRequest request) {
        if(info.getAbbreviation()==""|| info.getAbbreviation()==null || info.getAbbreviation() =="null"){
            return null;
        }else{
            Page<ReturnVisitInfo> page = new PageFactory<ReturnVisitInfo>().defaultPage();
            try {
                List<ReturnVisitInfo> list = new ArrayList<ReturnVisitInfo>();
                list = consultantDiagnosisService.selectPageConsultantByQuery(page, info);
                if (list.size() == 0) {
                    page.setCurrent(1);
                    list = consultantDiagnosisService.selectPageConsultantByQuery(page, info);
                }
                page.setTotal(consultantDiagnosisService.getQueryPagesCount(page, info));
                page.setRecords(list);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return super.packForBT(page);
        }
    }

    // 删除看诊
    @RequestMapping(value = "/delete_tcDiagnosis")
    @ResponseBody
    public int delete_tcDiagnosis(String id,String reservationsId, String abbreviation) throws Exception {
        return consultantDiagnosisService.delete_tcDiagnosis(id,reservationsId,abbreviation);
    }

    //编辑看诊
    @RequestMapping(value = "/update_tcDiagnosisOk", method = RequestMethod.POST)
    @ResponseBody
    public int update_tcDiagnosisOk(String id, String diagnosisContent ) throws Exception {
        return consultantDiagnosisService.update_tcDiagnosisOk(id,diagnosisContent);
    }
}